Ext.define('DragonApp.view.hero.Controller', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.hero',

    requires: [
        'DragonApp.util.Msg'
    ],

    onSubmitClick: function(button, e, options) {

        var me = this;
        var form = this.getView().getForm();
        if (!form.isValid()) return;

        var formValue = form.getValues();

        var grid = Ext.ComponentQuery.query('herogrid')[0];
        var store = grid.getStore();

        //数据仓库根据查询附加参数加载
        store.load({
            params: formValue,
            scope: this,
            callback: function(records, operation, success) {

                if (success == false) {
                    DragonApp.util.Msg.showToast('数据加载请求失败');
                    store.removeAll();
                } else if (success == true) {
                    if ("user-not-exist" == operation._response.type) {
                        DragonApp.util.Msg.showToast(operation._response.msg);
                        store.removeAll();
                    }
                }
            }
        });
    },

    onTextFieldSpecialKey: function(field, e, options) {
        if (e.getKey() === e.ENTER) {
            if (this.getView().getForm().isValid()) {
                this.onSubmitClick();
            }
        }
    },

    //============
    //技能解锁渲染
    //============
    lockStatusRender: function(value) {
        if ('未解锁' == value) {
            return '<span style="color:#B22222;font-weight:normal">' + value + '</span>';
        } else {
            return value;
        }
    }
});